#include "gatherTask.h"
#include "dht11.h"
#include "adc.h"
#include "Raindrop.h"
#include "GatherDataHandlerMemory.h"
#include <stdio.h>
void gatherTaskInit(){

	//初始化dht11
	DHT11_Init();
	
	//烟雾采集-ADCx_Init
	ADC1_Init();
	
	//雨滴传感器
	RainDrop_Init();
	
	//光明采集-ADCx_Init
	//ADC1_Init();
	
}


void gatherTaskTaskFun(void * p){
	
	while(1){
		GatherData  data;
		//1 采集温湿度
		/*u8 temp;  	    
		u8 humi;
		DHT11_Read_Data(&temp,&humi);
		printf("temp=%d,humi=%d\r\n",temp,humi);*/
		DHT11_Read_Data(&data.temp,&data.humi);
		
		//2 烟雾
		/*
		u16 smoke = Get_ADC_Value(ADC_Channel_9,10);
		smoke = smoke/40;
		printf("smoke=%d\r\n",smoke);*/
		u16 smoke = Get_ADC_Value(ADC_Channel_9,10);
		data.smoke = smoke;
		//3 雨滴
		/*
		if(RAINDROP_IN==0)
			printf("raindrop=%d\r\n",0);
		else 
			printf("raindrop=%d\r\n",1);*/
		u8 rainDrop = RAINDROP_IN==0 ? 0 : 1;
		data.raidrop = rainDrop;
		//4 光敏
		/*
		u16 sunshine = Get_ADC_Value(ADC_Channel_8,10);
		sunshine = 100 - sunshine/40;
		printf("sunshine=%d\r\n",sunshine);*/
		u16 sunshine = Get_ADC_Value(ADC_Channel_8,10);
		data.sunshine = sunshine;
		
		//调用数据处理模块进行处理
		dataHandle(&data);
		vTaskDelay(500);
	}
	
}

void gatherTaskCreate(){

	//创建一个启动任务
		BaseType_t result = xTaskCreate(
			gatherTaskTaskFun,
			GATHER_TASK_NAME,
			GATHER_TASK_STACK_DEPTH,
			NULL,
			GATHER_TASK_PRIORITY,
			NULL
		);
	
	
	if(result==pdPASS)
		printf("create gatherTask task sucess!\r\n");
	else
	  printf("create gatherTask task fail!\r\n");
	
}
	